<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <script type="text/javascript" src="lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="${ctx }/resources/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/css/H-ui.admin.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/lib/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx }/resources/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>添加活动</title>
</head>
<body>
<div class="pd-20">
    <form action="${ctx }/activity/addActivity" method="post" class="form form-horizontal" id="form-admin-add">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>栏目：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select class="select" name="categoryId" id="categoryId">
					<option value="${hotel.id}">请选择</option>
                    <c:forEach items="${categoryList}" var="hotel">
                        <option value="${hotel.id}">${hotel.categoryName}</option>
                    </c:forEach>
                </select>
				</span></div>
        </div>
        
         <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="title" name="title"
                       datatype="*2-16" nullmsg="标题不能为空">
            </div>
            <div class="col-1"></div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <script id="editor" type="text/plain" style="width:100%;height:400px;"></script>
                <input type="hidden" id="content" name="content">
            </div>
        </div>

     <div class="row cl">
			<label class="form-label col-2">标签：</label>
			<div class="formControls col-10">
			<c:forEach items="${tagList }" var="a">
				<dl class="permission-list">
					<dt>
						<label>
							<input type="checkbox" value="${a.id }" name="tagList" class="chosen-select" id="user-Character-0">
						${a.tagName }</label>
					</dt>
				</dl>
				</c:forEach>
			</div>
		</div>

        <div class="row cl">
            <div class="col-10 col-offset-2">
                <button class="btn btn-primary radius" type="button" id="save"><i class="Hui-iconfont">&#xe632;</i> 提交
                </button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">
                    &nbsp;&nbsp;返回&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="${ctx }/resources/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/icheck/jquery.icheck.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="${ctx }/resources/js/H-ui.js"></script>
<script type="text/javascript" src="${ctx }/resources/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/ueditor/1.4.3/ueditor.all.min.js"></script>
<script type="text/javascript" src="${ctx }/resources/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
    $(function () {

    	$("#save").click(function() {
    	    var param = {};
    	    
    	    // 收集参数 校验
    	    var categoryId = $("#categoryId").val();
    	    if(categoryId == '-1'){
    	    	autoCloseAlert("请选择栏目",500);
    	    	return false;
    	    }
    	    param["categoryId"] = categoryId;
    	    
    	    var title = $("#title").val();
    	   
    	    param["title"] = title;
    	    
    	    var arr = [];
    	    arr.push(ue.getContent());
    	    var content = arr.join("\n");
    	    
    	    // 简介
    	    var description = ue.getContentTxt().substring(0,500);
    	    
    	    // 标签
    	    var tagId = $(".chosen-select").val();
    	   
    	    	var ids = (tagId+"").split("\,");
    	    	var tagArray = [];
    	    	for(var i=0;i<ids.length;i++){
    	    		tagObj = {id:ids[i]};
    	    		tagArray.push(tagObj);
    	    	}
    	    	param["tagList"] = tagArray;
    	    	console.info(tagArray);

    	    // 保存文章
    	    $.ajax({
    	        type : "POST",
    	        url : '${ctx}/article/addArticle',
    	        data : 'param='+encodeURI(encodeURI(JSON.stringify(param)))+"&content="+encodeURI(encodeURI(content)).replace(/\&/g, "%26").replace(/\+/g, "%2B")+"&description="+encodeURI(encodeURI(description)),
    	        success  : function(data) {
    	        	parent.location.reload(); 
    	        	layer_close();
    			}
    	    });
    	});


    });

     
    var ue;
    $(function () {
        ue = UE.getEditor('editor');
    });

</script>
</body>
</html>